import axios from "axios"
import $ from 'jquery'
import adminUrls from "./urls"
const urls=adminUrls
//部门管理接口类
class DepartmentApis{
    /**
     * 获取部门详细信息
     * @param {*部门id} departmentId 
     * @param {*回调函数} dealRes 
     */
    searchForDepartmentById(departmentId,dealRes){
        axios.get(urls.searchForDepartmentByIdUrl,{params:{
            departmentId:departmentId
        }}).then(res=>dealRes(res.data))
    }
    /**
     * 获取部门信息树
     * @param {*回调函数} dealRes
     */
    getDepartments(dealRes){
        axios.get(urls.getDepartmentsUrl).then(res => dealRes(res.data))
    }
    /**
     * 获取一页部门人员信息
     * @param {*部门id} departmentId 
     * @param {*页码} pageNumber 
     * @param {*每页的容量} pageSize 
     * @param {*回调函数} dealRes 
     */
    getDepartmentsConsistent( departmentId,pageNumber,pageSize,dealRes){
        axios.get(urls.getDepartmentsConsistentUrl,{params:{
            departmentId:departmentId,
            pageNumber: pageNumber,
            pageSize:pageSize
        }}).then(res=>dealRes(res.data))
    }
    /**
     * 根据输入的字符模糊搜索满足条件的部门名称
     * @param {*输入的关键字符} key 
     * @param {*回调函数} dealRes 
     */
    searchForDepartmentName( key,dealRes){
        axios.get(urls.searchForDepartmentNameUrl,{params:{
            key:key
        }}).then(res=>dealRes(res.data))
    }
    /**
     * 编辑部门信息
     * @param {*部门id} departmentId 
     * @param {*部门详细信息} data 
     * @param {*回调函数} dealRes 
     */
    editDepartment(departmentId,data,dealRes){
        axios.post(urls.editDepartmentUrl,data,{params:{
            departmentId: departmentId
        }}).then(res=>dealRes(res.data))
    }
    /**
     * 查找非该部门的员工
     * @param {*页码} pageNumber 
     * @param {*每页的容量} pageSize 
     * @param {*关键字} key 
     * @param {*回调函数} dealRes 
     */
    searchPeopleOutOfDepartmentByKey( pageNumber,pageSize,key,dealRes){
        axios.get(urls.searchPeopleOutOfDepartmentByKeyUrl,{params:{
            pageNumber: pageNumber,
            pageSize:pageSize,
            key: key
        }}).then(res=>dealRes(res.data))
    }
    /**
     * 向部门增加员工
     * @param {*部门id} departmentId 
     * @param {*提交员工id号，数组} data 
     * @param {*回调函数} dealRes 
     */
    addPeopleToDepartment( departmentId,data,dealRes){
        axios.post(urls.addPeopleToDepartmentUrl,data,{params:{
            departmentId:departmentId
        }}).then(res=>dealRes(res.data))
    }
    /**
     * 删除部门员工
     * @param {部门id} departmentId 
     * @param {*员工id} personId 
     * @param {*回调函数} dealRes 
     */
    deletePersonFromDepartment(departmentId,personId,dealRes){
        axios.get(urls.deletePersonFromDepartmentUrl,{params:{
            departmentId: departmentId,
            personId: personId
        }}).then(res=>dealRes(res.data))
    }
    /**
     * 批量删除员工
     * @param {*部门信息} departmentId 
     * @param {*删除员工的id数组} data 
     * @param {*回调函数} dealRes 
     */
    deletePersonsFromDepartment(departmentId,data,dealRes){
        axios.post(urls.deletePersonsFromDepartmentUrl,data,{params:{
            departmentId:departmentId
        }}).then(res=>dealRes(res.data))
    }
    /**
     * 将员工设为部长
     * @param {*部门id} departmentId 
     * @param {*员工id} personId 
     * @param {*回调函数} dealRes 
     */
    setPersonToBeLeader(departmentId,personId,dealRes){
        axios.get(urls.setPersonToBeLeaderUrl,{params:{
            departmentId: departmentId,
            personId: personId
        }}).then(res=>dealRes(res.data))
    }
    /**
     * 撤销部长
     * @param {*部门id} departmentId 
     * @param {*员工id} personId 
     * @param {*回调函数} dealRes 
     */
    exemptLeader(departmentId,personId,dealRes){
        axios.post(urls.exemptLeader,{},{params:{
            departmentId:departmentId,
            personId:personId
        }}).then(res=>dealRes(res.data))
    }
    /**
     * 禁用员工
     * @param {*部门id} departmentId 
     * @param {*员工id} personId 
     * @param {*回调函数} dealRes 
     */
    shutPersonInDepartment(departmentId,personId,dealRes){
        axios.get(urls.shutPersonInDepartmentUrl,{params:{
            departmentId: departmentId,
            personId: personId
        }}).then(res=>dealRes(res.data))
    }
    /**
     * 创建部门
     * @param {*部门信息} data 
     * @param {*回调函数} dealRes 
     */
    createDepartment(data,dealRes){
        axios.post(urls.createDepartmentUrl,data).then(res=>dealRes(res.data))
    }
    /**
     * 删除部门
     * @param {*部门id} departmentId 
     * @param {*回调函数} dealRes 
     */
    deleteDepartment(departmentId,dealRes){
        axios.get(urls.deleteDepartmentUrl,{params:{
            departmentId:departmentId
        }}).then(res=>{dealRes(res.data)})
    }
}
//员工管理接口类
class StaffApis{
    /**
     * 获取全部行业类别
     * @param {*页码} pageNumber 
     * @param {*回调函数} dealRes 
     */
    getIndustryTypes(pageNumber,dealRes){
        axios.get(urls.getIndustryTypes,{params:{
            pageNumber:pageNumber,
        }}).then(res=>dealRes(res.data))
    }
    /**
     * 获取员工信息
     * @param {*页码} pageNum 
     * @param {*每页的容量} pageSize 
     * @param {*回调函数} dealRes 
     */
    personInfoShow(pageNum,pageSize,dealRes){
        axios.get(urls.personInfoShow,{params:{
            pageNum:pageNum,
            pageSize:pageSize
        }}).then(res=>dealRes(res.data))
    }
    /**
     * 添加员工
     * @param {*行业类别id} industryTypeId 
     * @param {*添加员工的id数组} data 
     * @param {*回调函数} dealRes 
     */
    personInfoAdd(industryTypeId,data,dealRes){
        axios.post(urls.personInfoAdd,data,{params:{
            industryTypeId:industryTypeId
        }}).then(res=>dealRes(res.data))
    }
    /**
     * 修改员工信息
     * @param {*行业类别id} industryTypeId 
     * @param {*修改员工的id数组} data 
     * @param {*回调函数} dealRes 
     */
    personInfoUpdate(industryTypeId,data,dealRes){
        axios.post(urls.personInfoUpdate,data,{params:{
            industryTypeId:industryTypeId
        }}).then(res=>dealRes(res.data))
    }
    /**
     * 模糊搜索员工
     * @param {*页码} pageNum 
     * @param {*每页的容量} pageSize 
     * @param {*搜索的关键字} key 
     * @param {*回调函数} dealRes 
     */
    personInfoSelect(pageNum,pageSize,key,dealRes){
        axios.get(urls.personInfoSelect,{params:{
            pageNum:pageNum,
            pageSize:pageSize,
            key:key
        }}).then(res=>dealRes(res.data))
    }
    /**
     * 删除一个员工
     * @param {*员工Id} personId 
     * @param {*回调函数} dealRes 
     */
    personInfoDelete(personId,dealRes){
        axios.post(urls.personInfoDelete,{},{params:{
            personId:personId
        }}).then(res=>dealRes(res.data))
    }
    /**
     * 删除一批员工
     * @param {*一批员工的id数组} data 
     * @param {*回调函数} dealRes 
     */
    personInfoDeleteMultiple(data,dealRes){
        axios.post(urls.personInfoDeleteMultiple,data).then(res=>dealRes(res.data))
    }
    /**
     * 禁用员工
     * @param {*员工id} personId 
     * @param {*回调函数} dealRes 
     */
    personInfoBan(personId,dealRes){
        axios.post(urls.personInfoBan,{},{params:{
            personId:personId
        }}).then(res=>dealRes(res.data))
    }
    /**
     * 上传员工信息
     * @param {*员工信息模板文件} data 
     * @param {*回调函数} dealRes 
     */
    
    personInfoImport(data,that,dealRes){
        // axios({
        //     url: urls.personInfoImport,
        //     type: 'post',
        //     data:data,
        //     headers:{
        //         "Content-type": "multipart/form-data"
        //     },
        //     success: () => {
        //         that.$Loading.finish();
        //     },
        //     error: () => {
        //         that.$Loading.error();
        //     }
        // }).then(res=>dealRes(res.data));
        axios.post(urls.personInfoImport,data,{headers:{
            "Content-type": "multipart/form-data"
        }},).then(res=>dealRes(res.data))
    }
}
//角色管理接口类
class RoleApis{
    /**
     * 获取所有角色信息
     * @param {*回调函数} dealRes 
     */
    getRoles(dealRes){
        axios.get(urls.getRoles).then(res=>dealRes(res.data))
    }
    /**
     * 获取所有的权限信息
     * @param {*回调函数} dealRes 
     */
    getAllAuthorities(dealRes){
        axios.get(urls.getAllAuthorities).then(res=>dealRes(res.data))
    }
    /**
     * 添加角色
     * @param {*添加角色的内容，包括角色权限和角色名称} data 
     * @param {*回调函数} dealRes 
     */
    addRole(data,dealRes){
        axios.post(urls.addRole,data).then(res=>dealRes(res.data))
    }
    /**
     * 删除角色
     * @param {*角色id} roleId 
     * @param {*回调函数} dealRes 
     */
    deleteRole(roleId,dealRes){
        axios.post(urls.deleteRole,{},{params:{
            roleId:roleId
        }}).then(res=>dealRes(res.data))
    }
    /**
     * 编辑角色信息
     * @param {*编辑后的角色权限和角色名称} data 
     * @param {*回调函数} dealRes 
     */
    updateRole(data,dealRes){
        axios.post(urls.updateRole,data).then(res=>dealRes(res.data))
    }
    /**
     * 获取关联员工信息
     * @param {*搜索关键字} keyWord 
     * @param {*角色ID} roleId 
     * @param {*页码} pageNumber 
     * @param {*页容量} pageSize 
     * @param {*回调函数} dealRes 
     */
    linkedPersons( keyWord,roleId,pageNumber,pageSize,dealRes){
        axios.get(urls.linkedPersons,{params:{
            keyWord:keyWord,
            roleId:roleId,
            pageNumber:pageNumber,
            pageSize:pageSize
        }}).then(res=>dealRes(res.data))
    }
      /**
     * 获取未关联员工信息
     * @param {*搜索关键字} keyWord 
     * @param {*角色ID} roleId 
     * @param {*页码} pageNumber 
     * @param {*页容量} pageSize 
     * @param {*回调函数} dealRes 
     */
    notLinkedPersons(keyWord,roleId,pageNumber,pageSize,dealRes){
        axios.get(urls.notLinkedPersons,{params:{
            keyWord:keyWord,
            roleId:roleId,
            pageNumber:pageNumber,
            pageSize:pageSize
        }}).then(res=>dealRes(res.data))
    }
    /**
     * 重置员工密码
     * @param {*员工信息} data 
     * @param {*回调函数} dealRes 
     */
    passwordReset(data,dealRes){
        axios.post(urls.passwordReset,data).then(res=>dealRes(res.data))
    }
    /**
     * 关联员工
     * @param {*员工信息} data 
     * @param {*关联角色id} roleId 
     * @param {*回调函数} dealRes 
     */
    personLinkToRole(data,roleId,dealRes){
        axios.post(urls.personLinkToRole,data,{params:{
            roleId:roleId
        }}).then(res=>dealRes(res.data))
    }

}
//视图管理接口类
class ViewApis{
    /**
     * 获取相应模块的视图
     * @param {*模块id} modelId 
     * @param {*回调函数} dealRes 
     */
    getView(modelId,dealRes){
        axios.get(urls.getView,{params:{
            modelId:modelId
        }}).then(res=>dealRes(res.data))
    }
    /**
     * 获取模块索引
     * @param {*回调函数} dealRes 
     */
    getModelIndexes(dealRes){
        axios.post(urls.getModelIndexes,{}).then(res=>dealRes(res.data))
    }
    /**
     * 更新视图
     * @param {*模块id} modelId 
     * @param {*视图di序号} data 
     * @param {*回调函数} dealRes 
     */
    updateView(modelId,data,dealRes){
        axios.post(urls.updateView,data,{params:{
            modelId:modelId
        }}).then(res=>dealRes(res.data))
    }
}
class ProjectApis{
    /**
     * 获取项目信息
     * @param {*页面} pageNumber 
     * @param {*页容量} pageSize 
     * @param {*回调函数} dealRes 
     */
    getProjectTypes(pageNumber,pageSize,dealRes){
        axios.get(urls.getProjectTypes,{params:{
            pageNumber:pageNumber,
            pageSize:pageSize
        }}).then(res=>dealRes(res.data))
    }
    /**
     * 修改项目信息
     * @param {*项目具体信息} data 
     * @param {*回调函数} dealRes 
     */
    updateProjectType(data,dealRes){
        axios.post(urls.updateProjectType,data).then(res=>dealRes(res.data))
    }
    /**
     * 添加项目名称
     * @param {*名称} name 
     * @param {*回调函数} dealRes 
     */
    addProjectType(name,dealRes){
        axios.get(urls.addProjectType,{params:{
            name:name
        }}).then(res=>dealRes(res.data))
    }
    /**
     * 删除项目
     * @param {*项目的id} data 
     * @param {*回调函数} dealRes 
     */
    deleteProjectType(data,dealRes){
        axios.post(urls.deleteProjectType,data).then(res=>dealRes(res.data))
    }
       /**
     * 获取全部行业类别
     * @param {*页码} pageNumber 
     * @param {*回调函数} dealRes 
     */
    getIndustryTypes(pageNumber,pageSize,dealRes){
        axios.get(urls.getIndustryTypes,{params:{
            pageNumber:pageNumber,
            pageSize:pageSize
        }}).then(res=>dealRes(res.data))
    }
    /**
     * 修改行业信息
     * @param {*行业的信息} data 
     * @param {*回调函数} dealRes 
     */
    updateIndustryType(data,dealRes){
        axios.post(urls.updateIndustryType,data).then(res=>dealRes(res.data))
    }
    /**
     * 添加行业信息
     * @param {*行业名称} name 
     * @param {*回调函数} dealRes 
     */
    addIndustryType(name,dealRes){
        axios.get(urls.addIndustryType,{params:{
            name:name
        }}).then(res=>dealRes(res.data))
    }
    /**
     * 删除行业类别
     * @param {*行业类别id} data 
     * @param {*回调函数} dealRes 
     */
    deleteIndustryType(data,dealRes){
        axios.post(urls.deleteIndustryType,data).then(res=>dealRes(res.data))
    }
}
const departmentApis=new DepartmentApis()
const staffApis=new StaffApis()
const roleApis=new RoleApis()
const viewApis=new ViewApis()
const projectApis=new ProjectApis()
export default {
    departmentApis:departmentApis,
    staffApis:staffApis,   
    roleApis:roleApis,
    viewApis:viewApis,
    projectApis:projectApis
};
